<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row class="cat_opt" :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryinfo.query" clearable>
            <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="##"></el-table-column>
        <el-table-column prop="order_number" label="订单号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="90"></el-table-column>
        <el-table-column label="是否付款" width="90">
          <template slot-scope="scope">

            <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="90"></el-table-column>
        <el-table-column label="创建时间" width="180">
          <template slot-scope="scope">
            {{scope.row.create_time | dataFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="showBox(scope.row)">编辑</el-button>
            <el-button type="primary" size="mini" icon="el-icon-location" @click="showProgressBos(scope.row)">
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[5, 15, 30, 50]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total" background>
      </el-pagination>
    </el-card>

    <el-dialog
      title="地址修改"
      :visible.sync="showBoxVisible">
      <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormRef" label-width="100px"
               @close="addressFormClose">
        <el-form-item label="省市区/县" prop="addres1">
          <el-cascader :options="cityData" v-model="addressForm.addres1"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="addres2">
          <el-input v-model="addressForm.addres2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="showBoxVisible = false">取 消</el-button>
    <el-button type="primary" @click="showBoxVisible = false">确 定</el-button>
  </span>
    </el-dialog>
    <el-dialog
      title="物流信息"
      :visible.sync="progressVisible">
      <el-timeline :reverse="true">
        <el-timeline-item v-for="(activity, index) in progressInfo" :key="index" :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
  import cityData from './citydata.js'

  export default {
    data () {
      return {
        orderList: [],
        queryinfo: {
          query: '',
          pagenum: 1,
          pagesize: 5
        },
        total: 0,
        addressForm: {},
        showBoxVisible: false,
        addressFormRules: {
          addres1: [{
            required: true,
            message: '请选择省市区/县',
            trigger: 'blur'
          }],
          addres2: [{
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }]
        },
        cityData,
        progressVisible: false,
        progressInfo: []
      }
    },
    created () {
      this.getOrderList()
    },
    methods: {
      handleSizeChange (newSize) {
        this.queryinfo.pagesize = newSize
        this.getOrderList()
      },
      handleCurrentChange (newNum) {
        this.queryinfo.pagenum = newNum
        this.getOrderList()
      },
      async getOrderList () {
        const { data: res } = await this.$http.get('orders', { params: this.queryinfo })
        if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
        this.orderList = res.data.goods
        this.total = res.data.total
      },
      // 展示修改地址
      showBox () {
        this.showBoxVisible = true
      },
      addressFormClose () {
        this.$refs.addressFormRef.resetFields()
        this.showBoxVisible = false
      },
      // 物流查询
      async showProgressBos () {
        const { data: res } = await this.$http.get('/kuaidi/1106975712662')
        if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
        this.progressInfo = res.data
        this.progressVisible = true
      }

    }
  }
</script>

<style lang="less" scoped>
  .el-table {
    margin: 15px 0;
  }

  .el-cascader {
    width: 100%;
  }
</style>
